import { createFormData } from "@pureadmin/utils";
import { http } from "@/utils/http";

export const check = (md5: string, sha256: string) => {
  return http.get<string>("/file/check", { md5, sha256 });
};

export const upload = (file: File) => {
  const formData = createFormData({ file: file });
  return http.upload<string>("/file/upload", {}, formData);
};

export const chunkUpload = (
  file: Blob,
  index: number,
  total: number,
  name: string
) => {
  const formData = createFormData({ file: file });
  return http.upload<number>(
    "/file/uploadChunk",
    { index, total, name },
    formData
  );
};

export const mergeFiles = (total: number, name: string) => {
  return http.post<string>("/file/merge", { total, name });
};

export const remove = (id: string) => {
  return http.request("delete", `/file/delete/${id}`);
};
